package com.github.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author shuang669539827@163.com
 */
@RestController
public class TestHystrixController {

    @Autowired
    private RestTemplate restTemplate;

    /**
     *  熔断器
     * @return
     */
    @GetMapping("/hello")
    @HystrixCommand(fallbackMethod = "userFallback")
    public String hello () throws InterruptedException {
        Thread.sleep(111111L);
        return restTemplate.getForEntity("http://HELLO-SERVICE/hello",String.class).getBody();
    }

    public String userFallback(){
        return " 报错了 ！  熔断";
    }

}



